﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
//using LTP.Accounts.Bus;
namespace HospitalManagement.Web.PatientInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int SysNo=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(SysNo);
				}
			}
		}
			
	private void ShowInfo(int SysNo)
	{
		HospitalManagement.BLL.PatientInfo bll=new HospitalManagement.BLL.PatientInfo();
		HospitalManagement.Model.PatientInfo model=bll.GetModel(SysNo);
		this.lblSysNo.Text=model.SysNo.ToString();
		this.txtFullName.Text=model.FullName;
		this.txtAnonymousName.Text=model.AnonymousName;
		this.txtBirthday.Text=model.Birthday.ToString();
		this.txtBirthPlace.Text=model.BirthPlace;
		this.txtAddress.Text=model.Address;
		this.txtMobile.Text=model.Mobile;
		this.txtPhone.Text=model.Phone;
		this.txtEmail.Text=model.Email;
		this.txtContact.Text=model.Contact;
		this.txtRelation.Text=model.Relation;
		this.txtSurvival.Text=model.Survival;
		this.txtSick.Text=model.Sick;
		this.txtprogressionTime.Text=model.progressionTime;
		this.txtComeInTime.Text=model.ComeInTime.ToString();
		this.txtDisabled.Text=model.Disabled.ToString();
		this.txtIndate.Text=model.Indate.ToString();
		this.txtInUser.Text=model.InUser;
		this.txtEditDate.Text=model.EditDate.ToString();
		this.txtEditUser.Text=model.EditUser;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtFullName.Text.Trim().Length==0)
			{
				strErr+="FullName不能为空！\\n";	
			}
			if(this.txtAnonymousName.Text.Trim().Length==0)
			{
				strErr+="AnonymousName不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtBirthday.Text))
			{
				strErr+="Birthday格式错误！\\n";	
			}
			if(this.txtBirthPlace.Text.Trim().Length==0)
			{
				strErr+="BirthPlace不能为空！\\n";	
			}
			if(this.txtAddress.Text.Trim().Length==0)
			{
				strErr+="Address不能为空！\\n";	
			}
			if(this.txtMobile.Text.Trim().Length==0)
			{
				strErr+="Mobile不能为空！\\n";	
			}
			if(this.txtPhone.Text.Trim().Length==0)
			{
				strErr+="Phone不能为空！\\n";	
			}
			if(this.txtEmail.Text.Trim().Length==0)
			{
				strErr+="Email不能为空！\\n";	
			}
			if(this.txtContact.Text.Trim().Length==0)
			{
				strErr+="Contact不能为空！\\n";	
			}
			if(this.txtRelation.Text.Trim().Length==0)
			{
				strErr+="Relation不能为空！\\n";	
			}
			if(this.txtSurvival.Text.Trim().Length==0)
			{
				strErr+="Survival不能为空！\\n";	
			}
			if(this.txtSick.Text.Trim().Length==0)
			{
				strErr+="Sick不能为空！\\n";	
			}
			if(this.txtprogressionTime.Text.Trim().Length==0)
			{
				strErr+="progressionTime不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtComeInTime.Text))
			{
				strErr+="ComeInTime格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtDisabled.Text))
			{
				strErr+="Disabled格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtIndate.Text))
			{
				strErr+="Indate格式错误！\\n";	
			}
			if(this.txtInUser.Text.Trim().Length==0)
			{
				strErr+="InUser不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtEditDate.Text))
			{
				strErr+="EditDate格式错误！\\n";	
			}
			if(this.txtEditUser.Text.Trim().Length==0)
			{
				strErr+="EditUser不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int SysNo=int.Parse(this.lblSysNo.Text);
			string FullName=this.txtFullName.Text;
			string AnonymousName=this.txtAnonymousName.Text;
			DateTime Birthday=DateTime.Parse(this.txtBirthday.Text);
			string BirthPlace=this.txtBirthPlace.Text;
			string Address=this.txtAddress.Text;
			string Mobile=this.txtMobile.Text;
			string Phone=this.txtPhone.Text;
			string Email=this.txtEmail.Text;
			string Contact=this.txtContact.Text;
			string Relation=this.txtRelation.Text;
			string Survival=this.txtSurvival.Text;
			string Sick=this.txtSick.Text;
			string progressionTime=this.txtprogressionTime.Text;
			DateTime ComeInTime=DateTime.Parse(this.txtComeInTime.Text);
			int Disabled=int.Parse(this.txtDisabled.Text);
			DateTime Indate=DateTime.Parse(this.txtIndate.Text);
			string InUser=this.txtInUser.Text;
			DateTime EditDate=DateTime.Parse(this.txtEditDate.Text);
			string EditUser=this.txtEditUser.Text;


			HospitalManagement.Model.PatientInfo model=new HospitalManagement.Model.PatientInfo();
			model.SysNo=SysNo;
			model.FullName=FullName;
			model.AnonymousName=AnonymousName;
			model.Birthday=Birthday;
			model.BirthPlace=BirthPlace;
			model.Address=Address;
			model.Mobile=Mobile;
			model.Phone=Phone;
			model.Email=Email;
			model.Contact=Contact;
			model.Relation=Relation;
			model.Survival=Survival;
			model.Sick=Sick;
			model.progressionTime=progressionTime;
			model.ComeInTime=ComeInTime;
			model.Disabled=Disabled;
			model.Indate=Indate;
			model.InUser=InUser;
			model.EditDate=EditDate;
			model.EditUser=EditUser;

			HospitalManagement.BLL.PatientInfo bll=new HospitalManagement.BLL.PatientInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
